package com.example.demo2.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo2.util.TransferPage;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;

/**
 * @description This class is for user interaction between users and flight information display page
 * @version 2.0
 */

public class InfoController {
    @FXML
    private Button backButton;

    @FXML
    private TextArea text1;

    @FXML
    private TextArea text2;

    @FXML
    private Button confirmButton;

    @FXML
    public void setText1(JSONObject object){
        TransferPage.transfer("flight-info", "Flight Info", 617, 745);
        String departure = object.getString("departure");
        String Date = object.getString("Date");
        String boardingTime = object.getString("boardingTime");
        String duration = object.getString("duration");
        String theClass = object.getString("theClass");
        String destination = object.getString("destination");
        String text = departure + "-------" + destination + "\n" +
                Date + "\n" +
                boardingTime + "\n" +
                duration + "\n" +
                "VIP Class" + theClass;
        text1.setText(text);
    }

    @FXML
    public void setText2(JSONObject object){
        String departure = object.getString("departure");
        String Date = object.getString("Date");
        String boardingTime = object.getString("boardingTime");
        String duration = object.getString("duration");
        String theClass = object.getString("theClass");
        String destination = object.getString("destination");
        String text = departure + "-------" + destination + "\n" +
                Date + "\n" +
                boardingTime + "\n" +
                duration + "\n" +
                "VIP Class" + theClass;
        text2.appendText(text);
    }

    public void backController(ActionEvent event) {
        Stage primaryStage = (Stage) backButton.getScene().getWindow();
        primaryStage.hide();
        TransferPage.transfer("passenger", "Passenger Login",400,600);
    }

    public void confirmController(ActionEvent event) {

        Stage primaryStage = (Stage) confirmButton.getScene().getWindow();
        primaryStage.hide();
        TransferPage.transfer("seat-view", "Seat Selector",613,566);
    }
}
